package com.wn.pettyloan.controller;

import com.wn.pettyloan.entity.CheckUp;
import com.wn.pettyloan.entity.Contract;
import com.wn.pettyloan.entity.ContractTemplate;
import com.wn.pettyloan.service.CheckUpService;
import com.wn.pettyloan.service.ContractService;
import com.wn.pettyloan.service.DebitService;
import com.wn.pettyloan.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @program: pettyloan
 * @ClassName CheckUpController
 * @author: lwb
 * @create: 2022-12-06 21:51
 **/
@RestController
@RequestMapping("/checkup")
public class CheckUpController {
    @Autowired
    private CheckUpService checkUpService;

    @Autowired
    private ContractService contractService;
    @Autowired
    private DebitService debitService;

    @PostMapping("/checked1")
    public Result check1(@RequestBody CheckUp checkUp){
        //checkUp 是否取到了emp_id?审核表这里需要拿到审核员工的Id
        //完成一审审核表生成操作
        checkUpService.check2(checkUp);
        if(checkUp.getCheckResult().equals(1)){
            //修改借款表中审核状态为,1审已过11; 这里不要验证debit存在不了没意义
            debitService.updateStatusById(checkUp.getDebitId(),11);
            //修改借款表中审批金额
            debitService.updateApproveNumById(checkUp.getDebitId(),checkUp.getCheckFee());
        }else {
            //修改借款表状态，1审未通过
            debitService.updateStatusById(checkUp.getDebitId(),12);
        }
        return Result.ok();
    }

    /*后台经理2审核接口，通过与拒绝都是这个接口*/
    @PostMapping("/checked2")
    public Result check2(@RequestBody CheckUp checkUp){
        //checkUp 是否取到了emp_id?审核表这里需要拿到审核员工的Id
        //完成二审审核表生成操作
        checkUpService.check2(checkUp);
        if(checkUp.getCheckResult().equals(1)){
            //修改借款表中审核状态为,二审已过21; 这里不要验证debit存在不了没意义
            debitService.updateStatusById(checkUp.getDebitId(),21);
            //修改借款表中审批金额
            debitService.updateApproveNumById(checkUp.getDebitId(),checkUp.getCheckFee());
        }else {
            //修改借款表状态，二审未通过
            debitService.updateStatusById(checkUp.getDebitId(),22);
        }
        return Result.ok();
    }

}
